package com.rt.schedulenew.utils.util;

import com.rt.schedulenew.utils.base.ConstantsUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 用于超声诊室预约时两个诊室互相切换
 * @author : huzhao
 * @create 2023/6/26 16:45
 */
@Slf4j
public class ConsultingRoomChooseUtil {

    private static final Lock l = new ReentrantLock();

    public static String getUltrasonicRoom() {
        l.lock();
        try {
            // 房间A: 1496271
            // 房间B: 1496278
            Integer ultrasonic = (Integer) EhCacheUtil.get(ConstantsUtil.EhCacheName.roomCache.name(), "ULTRASONIC");
            if (ultrasonic == null || ultrasonic % 2 != 0) {
                EhCacheUtil.put(ConstantsUtil.EhCacheName.roomCache.name(), "ULTRASONIC", 2);
                return "1496271";
            }
            EhCacheUtil.put(ConstantsUtil.EhCacheName.roomCache.name(), "ULTRASONIC", 1);
            return "1496278";
        }catch (Exception e) {
            //log.error(e.toString());
            return "";
        }finally {
            l.unlock();
        }

    }


}
